package com.etooling.pdm.repository;

import com.etooling.framework.repository.BaseRepository;
import com.etooling.pdm.entity.GoodsPropValues;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Repository
public interface GoodsPropValuesRepository extends BaseRepository<GoodsPropValues> {


    @Query(nativeQuery = true, value = "select count(1) from pdm.t_goods_prop_values v where v.goods_type_properties_id =?1 and ((v.code =?2 and v.p_value <>?3) or (v.code <>?2 and v.p_value =?3))")
    Integer getCountByCodeAndValue(String typePropertiesId, String code, String pValue);


    /**
     * 根据产品属性配置id 拿出所有的配置信息
     *
     * @param settingIds
     * @return
     */
    @Query(nativeQuery = true, value = "select value, code, setting_id from pdm.t_goods_prop_values where setting_id in ?1")
    List<Map<String, Object>> getInfoBySettingIds(List<String> settingIds);


    /**
     * 获取。value,code,setting_id
     *
     * @param goodsIds
     * @return
     */
    @Query(nativeQuery = true, value = "select id, code, goods_id, value, setting_id, goods_type_id from pdm.t_goods_prop_values where goods_id in ?1 ")
    List<Map<String, Object>> getInfoByGoodsId(List<String> goodsIds);


}
